﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class OutstockDetailedInfo
    {
        /// <summary>
        /// ID自增主键
        /// </summary>
        public int ID
        {
            get;
            set;
        }
        /// <summary>
        /// 入库日期
        /// </summary>
        public DateTime OutstockDt
        {
            get;
            set;
        }
        /// <summary>
        /// 仓库
        /// </summary>
        public int Warehouse_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 班组
        /// </summary>
        public int Group_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 食材
        /// </summary>
        public int Goods_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 数量
        /// </summary>
        public decimal Count
        {
            get;
            set;
        }
        /// <summary>
        /// 单价
        /// </summary>
        public decimal Price
        {
            get;
            set;
        }
        /// <summary>
        /// 金额
        /// </summary>
        public decimal Amount
        {
            get;
            set;
        }
        /// <summary>
        /// 领用人
        /// </summary>
        public string LeadMan
        {
            get;
            set;
        }
        /// <summary>
        /// 记录时间
        /// </summary>
        public DateTime RecordDateTime
        {
            get;
            set;
        }
        /// <summary>
        /// 经办人
        /// </summary>
        public string OperatorID
        {
            get;
            set;
        }

        /// <summary>
        /// 订单编号
        /// </summary>
        public string OrderNo
        {
            get;
            set;
        }

        private DataAccessOutstockDetailed outStockDetailAccess;
        private int rowcount = 0;
        public int _rowcount
        {
            get { return rowcount; }
        }

        public OutstockDetailedInfo()
        { }


        public OutstockDetailedInfo(bool isgetcount)
        {
            outStockDetailAccess = new DataAccessOutstockDetailed();
            if (isgetcount)
            {
                rowcount = GetOutstockDetailedCount("");
            }
        }

        /// <summary>
        /// 获取批号
        /// </summary>
        /// <returns></returns>
        public string GetOutstockDetailedOrderNo()
        {
            return "";// outStockDetailAccess.GetOutstockDetailedOrderNo();

        }
        /// <summary>
        /// 食材出库数量
        /// </summary>
        /// <returns></returns>
        public int GetOutstockDetailedCount(string Condition)
        {
            return outStockDetailAccess.GetOutstockDetailedCount(Condition);
        }


        /// <summary>
        /// 保存食材明细
        /// </summary>
        /// <param name="idab"></param>
        /// <returns></returns>
        public int SaveOutstockDetailed(OutstockDetailedInfo outDetail)
        {
            object[] idpara = new object[] {outDetail.ID,outDetail.OutstockDt,outDetail.Warehouse_ID, outDetail.Group_ID, 
                                            outDetail.Goods_ID, outDetail.Count,outDetail.Price,outDetail.Amount,outDetail.LeadMan,
                                            outDetail.RecordDateTime,outDetail.OperatorID,outDetail.OrderNo };
            return outStockDetailAccess.SaveOutstockDetailed(idpara);
        }

        /// <summary>
        /// 获取食材明细不分页
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<OutstockDetailedInfo> GetAllOutstockDetailed(string condition)
        {
            IList<OutstockDetailedInfo> Idalist = new List<OutstockDetailedInfo>();
            DataSet ds = outStockDetailAccess.GetAllOutstockDetailed(condition);
            OutstockDetailedInfo ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new OutstockDetailedInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    OutstockDt = Convert.ToDateTime(item[1]),
                    Warehouse_ID = Convert.ToInt32(item[2]),
                    Group_ID = Convert.ToInt32(item[3]),
                    Goods_ID = Convert.ToInt32(item[4]),
                    Count = Convert.ToDecimal(item[5]),
                    Price = Convert.ToDecimal(item[6]),
                    Amount = Convert.ToDecimal(item[7]),
                    LeadMan = item[8].ToString(),
                    RecordDateTime = Convert.ToDateTime(item[9]),
                    OperatorID = item[10].ToString(),
                    OrderNo = item[11].ToString()
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }


        /// <summary>
        /// 根据明细ID获取明细实体类
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public OutstockDetailedInfo GetAllOutstockDetailed(int Id)
        {
            DataRow item = outStockDetailAccess.GetOutstockDetailed(Id);
            OutstockDetailedInfo ideinfo = new OutstockDetailedInfo()
            {
                ID = Convert.ToInt32(item[0]),
                OutstockDt = Convert.ToDateTime(item[1]),
                Warehouse_ID = Convert.ToInt32(item[2]),
                Group_ID = Convert.ToInt32(item[3]),
                Goods_ID = Convert.ToInt32(item[4]),
                Count = Convert.ToDecimal(item[5]),
                Price = Convert.ToDecimal(item[6]),
                Amount = Convert.ToDecimal(item[7]),
                LeadMan = item[8].ToString(),
                RecordDateTime = Convert.ToDateTime(item[9]),
                OperatorID = item[10].ToString(),
                OrderNo = item[11].ToString()
            };
            return ideinfo;
        }


        /// <summary>
        /// 获取食材明细分页
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<OutstockDetailedInfo> GetAllOutstockDetailed(string condition, int pagesize, int startindex)
        {
            IList<OutstockDetailedInfo> Idalist = new List<OutstockDetailedInfo>();
            DataSet ds = outStockDetailAccess.GetAllOutstockDetailed(condition, pagesize, startindex);
            OutstockDetailedInfo ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new OutstockDetailedInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    OutstockDt = Convert.ToDateTime(item[1]),
                    Warehouse_ID = Convert.ToInt32(item[2]),
                    Group_ID = Convert.ToInt32(item[3]),
                    Goods_ID = Convert.ToInt32(item[4]),
                    Count = Convert.ToDecimal(item[5]),
                    Price = Convert.ToDecimal(item[6]),
                    Amount = Convert.ToDecimal(item[7]),
                    LeadMan = item[8].ToString(),
                    RecordDateTime = Convert.ToDateTime(item[9]),
                    OperatorID = item[10].ToString(),
                    OrderNo = item[11].ToString()
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }



        /// <summary>
        /// 删除食材出库数量
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public int DeleteOutstockDetailed(int Id)
        {
            return outStockDetailAccess.DeleteOutstockDetailed(Id);
        }

        /// <summary>
        /// 生成批量输入编号
        /// </summary>
        /// <returns></returns>
        public virtual string BuliderOrderNo()
        {
            return outStockDetailAccess.BuilderOrderNo();
        }

        public bool OutStockYzh(int GID, decimal Count, decimal Price, string AddEdit, decimal OldCount)
        {
            return outStockDetailAccess.OutStockYzh(GID, Count, Price, AddEdit, OldCount);
        }
    }
}
